---
layout: "default"
title: "max"
description: "Swift documentation for 'max': Returns the greater of two comparable values."
keywords: "max,func,swift,documentation"
root: "/v4.2"
---

<div class="declaration" id="func-max-t_-t_-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-max-t_-t_-t">func max&lt;T&gt;(<wbr>_:<wbr> T, _: T)</a>
        
<div class="comment collapse" id="comment-func-max-t_-t_-t"><div class="p">
    <p>Returns the greater of two comparable values.</p>

<p><strong>Parameters:</strong>
  <strong>x:</strong> A value to compare.
  <strong>y:</strong> Another value to compare.
<strong>Returns:</strong> The greater of <code>x</code> and <code>y</code>. If <code>x</code> is equal to <code>y</code>, returns <code>y</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func max&lt;T&gt;(_ x: T, _ y: T) -&gt; T where T : Comparable</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-max-t_-t_-t_-t_-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-max-t_-t_-t_-t_-t">func max&lt;T&gt;(<wbr>_:<wbr> T, _:<wbr> T, _:<wbr> T, _: T...)</a>
        
<div class="comment collapse" id="comment-func-max-t_-t_-t_-t_-t"><div class="p">
    <p>Returns the greatest argument passed.</p>

<p><strong>Parameters:</strong>
  <strong>x:</strong> A value to compare.
  <strong>y:</strong> Another value to compare.
  <strong>z:</strong> A third value to compare.
  <strong>rest:</strong> Zero or more additional values.
<strong>Returns:</strong> The greatest of all the arguments. If there are multiple equal
  greatest arguments, the result is the last one.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func max&lt;T&gt;(_ x: T, _ y: T, _ z: T, _ rest: T...) -&gt; T where T : Comparable</code>
    
    
</div></div>
</div>
